package com.cloud.jdkTest;
//synchronized是否保证可见性
public class SyncVisibility {
    private static Object object = new Object();

    private static boolean flag = true;

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            while (flag) {
//                synchronized (object) {
//                    System.out.println("the value of flag is " + flag);
//                }
                System.out.println("I never feel the change of the flag");
            }
            System.out.println("Other thread has changed the flag, I can feel!");
        }).start();

        Thread.sleep(1000);

        new Thread(() -> {
            flag = false;
            System.out.println("I have changed the flag value!");
        }).start();
    }
}
